package slh.comment;

import java.sql.Timestamp;

public class comment {
    private int commentId;
    private String userId;
    private int contentId;
    private String contentType; // "movie" 或 "book"
    private int rating; // 1-5星
    private String commentText;
    private Timestamp createdAt;
    private boolean isDeleted;
    private String avatar; // 用户头像URL（非数据库字段，用于显示）

    // 无参构造器
    public comment() {
    }

    // 带参构造器
    public comment(int commentId, String userId, int contentId, String contentType,
                   int rating, String commentText, Timestamp createdAt, boolean isDeleted) {
        this.commentId = commentId;
        this.userId = userId;
        this.contentId = contentId;
        this.contentType = contentType;
        this.rating = rating;
        this.commentText = commentText;
        this.createdAt = createdAt;
        this.isDeleted = isDeleted;
    }

    // Getter 和 Setter 方法
    public int getCommentId() {
        return commentId;
    }

    public void setCommentId(int commentId) {
        this.commentId = commentId;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public int getContentId() {
        return contentId;
    }

    public void setContentId(int contentId) {
        this.contentId = contentId;
    }

    public String getContentType() {
        return contentType;
    }

    public void setContentType(String contentType) {
        this.contentType = contentType;
    }

    public int getRating() {
        return rating;
    }

    public void setRating(int rating) {
        if (rating < 1 || rating > 5) {
            throw new IllegalArgumentException("评分必须在1-5之间");
        }
        this.rating = rating;
    }

    public String getCommentText() {
        return commentText;
    }

    public void setCommentText(String commentText) {
        if (commentText != null && commentText.length() > 1000) {
            throw new IllegalArgumentException("评论内容过长");
        }
        this.commentText = commentText;
    }

    public Timestamp getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Timestamp createdAt) {
        this.createdAt = createdAt;
    }

    public boolean isDeleted() {
        return isDeleted;
    }

    public void setDeleted(boolean deleted) {
        isDeleted = deleted;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    // 实用方法
    public String getRatingStars() {
        StringBuilder stars = new StringBuilder();
        for (int i = 1; i <= 5; i++) {
            stars.append(i <= rating ? "★" : "☆");
        }
        return stars.toString();
    }

    // toString() 方法
    @Override
    public String toString() {
        return "Comment{" +
                "commentId=" + commentId +
                ", userId='" + userId + '\'' +
                ", contentId=" + contentId +
                ", contentType='" + contentType + '\'' +
                ", rating=" + rating +
                ", commentText='" + commentText + '\'' +
                ", createdAt=" + createdAt +
                ", isDeleted=" + isDeleted +
                '}';
    }
}